#include"order.h"
void main()
{
	clock_t begin, end;
	double cost;
	int array[MAX], dd[MAX];
	int n, s, q, ch, x = 0;
	n = MAX;
	srand((int)time(0));
	for (s = 0; s < MAX; s++)
		array[s] = rand() % 70000 + 30000;
	printf("原始数列如下：\n");
	for (s = 0; s < MAX; s++)
	{
		printf("%d ", array[s]);
		x++;
		if (x == 20)
		{
			printf("\n");
			x = 0;
		}
	}
	x = 0;
	printf("1--直接插入排序\n");
	printf("2--希尔排序\n");
	printf("3--冒泡排序\n");
	printf("4--简单选择排序\n");
	printf("5--快速排序\n");
	printf("6--堆排序\n");
	printf("7--归并排序\n");
	printf("8--基数排序\n");
	printf("请选择（1-8）\n");
	scanf_s("%d", &ch);
	switch (ch)
	{
	case 1:
		printf("直接插入排序结果：\n");
		//开始记录
		begin = clock();
		InsertSort(array, n);
		//结束记录
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	case 2:
		printf("希尔排序结果：\n");
		s = n;
		q = 0;
		while (s > 1)
		{
			dd[q++] = s / 2;
			s = s / 2;
		}
		begin = clock();
		ShellSort(array, n, dd, q);
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	case 3:
		printf("冒泡排序结果：\n");
		begin = clock();
		BubbleSort(array, n);
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	case 4:
		printf("简单选择排序结果:\n");
		begin = clock();
		SelectSort(array, n);
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break; 
	case 5:
		printf("快速排序结果：\n");
		begin = clock();
		QuickSort(array, 0, n - 1);//传的是数组下标，所以使用n-1
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	
	case 6:
		printf("堆排序结果：\n");
		begin = clock();
		HeapSort(array, n);
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	case 7:
		printf("归并排序结果：\n");
		begin = clock();
		MergeSort(array,n);
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	case 8:
		printf("基数排序结果：\n");
		begin = clock();
		radixSort(array);
		end = clock();
		cost = (double)(end - begin) / CLOCKS_PER_SEC;
		printf("constant CLOCKS_PER_SEC is: %ld, time cost is: %lf secs\n", CLOCKS_PER_SEC, cost);
		break;
	default:
		return;
	}
	for (s = 0; s <= n - 1; s++)
	{
		printf("%d ", array[s]);
		x++;
		if (x == 20)
		{
			printf("\n");
			x = 0;
		}
	}
	printf("\n");
}
